package com.woniu.controller;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.woniu.service.WechatService;
import com.woniu.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;


@Slf4j
@RestController("WeChatController")
@RequestMapping("/wechat")
@Api(tags = "微信")
public class WeChatController {

    @Autowired
    private WechatService wechatService;


    /**
     * 微信登录小程序授权登录
     */
    @ApiOperation(value = "微信登录小程序授权登录")
    @PostMapping(value = "/authorize/program/login")
    @ApiImplicitParams({@ApiImplicitParam(name = "code",dataType = "String", paramType = "body",
            value = "微信code", required = true),
            @ApiImplicitParam(name = "shareId",dataType = "String", paramType = "body",
                    value = "邀请人的用户ID，有则传，没有则不用传", required = true),})
    public TokenVO programLogin(@RequestBody JSONObject code){
        return wechatService.weChatAuthorizeProgramLogin(code);
    }


    @ApiOperation(value = "记录订阅")
    @PostMapping("/subscription/{templateId}")
    @ApiImplicitParams({@ApiImplicitParam(name = "templateId",dataType = "Integer", paramType = "path",
            value = "模板表ID1是红包通知，2是邀请结果", required = true),})
    public boolean subscription(@PathVariable("templateId") Integer templateId){
        return wechatService.subscription(templateId);
    }




}



